<?php

/**
 * 操作数据库的接口
 * Interface db
 */
interface db {
    public function conn();
}

/**
 * 数据库工厂类接口
 * Interface Factory
 */
interface Factory {
    public function createDB();
}

/**
 * mysql工厂类
 * Class mysqlFactory
 */
class mysqlFactory implements Factory {
    public function createDB()
    {
        return new dbmysql();
    }
}

/**
 * sqllite工厂类
 * Class sqlliteFactory
 */
class sqlliteFactory implements Factory {
    public function createDB()
    {
        return new dbsqllite();
    }
}

/**
 * 新追加的oracle拓展类
 * Class oracleFactory
 */
class oracleFactory implements Factory {
    public function createDB()
    {
        return new dboracle();
    }
}

/**
 *一下是具体的每个数据库的操作类
 * Class dbmysql
 */
class dbmysql implements db {
    public function conn()
    {
        echo '连接上了MySQL';
    }
}

class dbsqllite implements db {
    public function conn()
    {
        echo '连接上了SQLlite';
    }
}

class dboracle implements db {
    public function conn()
    {
        echo '连接上了oracle';
    }
}

/**
 * 客户端调用
 */
$fact = new mysqlFactory();
$conn = $fact->createDB();
$conn->conn();

$fact = new sqlliteFactory();
$conn = $fact->createDB();
$conn->conn();

$fact = new oracleFactory();
$conn = $fact->createDB();
$conn->conn();